package com.luyuan.web.converter;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;

import org.springframework.stereotype.Component;

@Component("htmlConverter")
public class HTMLConverter implements Converter {

    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        return null;
    }

    @Override
    public String getAsString(FacesContext context, UIComponent component, Object value) {
        if (value == null) {
            return null;
        }

        String s = "";
        if (value instanceof String) {
            s = (String) value;
        }
        else {
            s = String.valueOf(value);
        }

        return s.replaceAll("\r\n", "<br/>").replaceAll("\n", "<br/>");
    }
}
